<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>a:{{a}}</p>
        <p>b:{{b}}</p>
        <button @click="samA">a++</button>
        <button @click="samB">b++</button>
    {{age}} 
    <button @click="age++">add</button> 
    {{ageFun}}  
    </div>
    <script>
        new Vue ({
            el:"#app",
            data(){
                return{
                    name:'',
                    age:'',
                    a:0,
                    b:0
                }
            },
            watch:{
                age(val,old){
                    // console.log(val,old);
                    if(val>=18){
                        alert("危险数据过大")
                        this.age=18
                    }
                }
            },
            methods:{
                //   ageFun(){
                //       console.log(111);
                //       return  111
                // }
                samA(){
                    console.log('a执行了');
                    return this.a++
                },
                samB(){
                    console.log('b执行了');
                    return this.b++
                }

            },
            computed:{
                // 计算属性：
                // 1.调用的时候不能加括号
                // 2.计算属性一定要有return
                ageFun(){
                    //   console.log(111);
                      return  111
                }
            }
        })
    </script>
</body>
</html>